package com.xjtu.platform.security.updatePassword.Impl;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.security.updatePassword.UpdatePasswordDto;
import com.xjtu.platform.security.updatePassword.UpdatePasswordService;
import com.xjtu.platform.security.updatePassword.UserDto;
import com.xjtu.platform.security.updatePassword.dao.UpdatePasswordDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional
public class UpdatePasswordServiceImpl implements UpdatePasswordService {

    @Resource
    private UpdatePasswordDao updatePasswordDao;

    @Override
    public boolean updatePwd(UpdatePasswordDto updatePasswordDto,String user_id) {
        try {
            updatePasswordDao.updatePwd(updatePasswordDto,user_id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Map<String, Object> getEmail(UserDto userDto, String user_id) {
        return Utils.getPage(userDto,()->updatePasswordDao.getEmail(user_id));
    }

    @Override
    public int getFlag(String user_id) {
        try {
            return updatePasswordDao.getFlag(user_id);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public long getCachetime(String user_id) {
        try {
            return updatePasswordDao.getCachetime(user_id);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
